﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Windows;
using System.Windows.Input;
using GMap.NET.WindowsPresentation;
using GMap.NET;

namespace RZD_maps.Modules.Map.ViewModel
{
    public class Map : GMapControl
    {

        static Map()
        {
            CommandManager.RegisterClassCommandBinding(
    typeof(Map), new CommandBinding(ComponentCommands.MoveDown, (sender, e) => Pan(sender, e.Command, 0, -1)));
            CommandManager.RegisterClassCommandBinding(
                typeof(Map), new CommandBinding(ComponentCommands.MoveLeft, (sender, e) => Pan(sender, e.Command, 1, 0)));
            CommandManager.RegisterClassCommandBinding(
                typeof(Map), new CommandBinding(ComponentCommands.MoveRight, (sender, e) => Pan(sender, e.Command, -1, 0)));
            CommandManager.RegisterClassCommandBinding(
                typeof(Map), new CommandBinding(ComponentCommands.MoveUp, (sender, e) => Pan(sender, e.Command, 0, 1)));

            CommandManager.RegisterClassCommandBinding(
                typeof(Map), new CommandBinding(NavigationCommands.DecreaseZoom, (sender, e) => ((Map)sender).Zoom--));
            CommandManager.RegisterClassCommandBinding(
                typeof(Map), new CommandBinding(NavigationCommands.IncreaseZoom, (sender, e) => ((Map)sender).Zoom++));

        }

        public static void Pan(object sender, ICommand command, double X, double Y)
        {
            Map instance = (Map)sender;
            PointLatLng p = instance.Position;
            RectLatLng viewArea = instance.CurrentViewArea;
            double width = viewArea.WidthLng;
            double height = viewArea.HeightLat;
            PointLatLng delta = new PointLatLng(Y*height / 10, X*width / 10);
            p.Lat = p.Lat+delta.Lat;
            p.Lng = p.Lng - delta.Lng;
            instance.Position = p;
        }
    }
}
